<template>
  <el-container
      class="layout-container-demo"
      style=" border: 1px solid #eee"
  >
    <el-aside width="200px">
      <el-row>
        <el-col :span="8">
          <div class="grid-content bg-purple">
          </div>
        </el-col>
        <el-col :span="16">
          <div class="grid-content bg-purple-light">
            任务ID
          </div>
        </el-col>
      </el-row>
      <el-scrollbar>
        <el-row v-for="(value,index) in roughTaskList " :key="index">
          <el-col :span="8" @click="playVideo(value.id); target=value.target.trim().split(',')">
            <div class="grid-content bg-purple">
              {{ index + 1 }}
            </div>
          </el-col>
          <el-col :span="16" @click="playVideo(value.id);target=value.target.trim().split(',')">
            <div class="grid-content bg-purple-light">
              {{ value.id }}
            </div>
          </el-col>
        </el-row>
      </el-scrollbar>


    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px"
            >
              <setting
              />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>View</el-dropdown-item>
                <el-dropdown-item>Add</el-dropdown-item>
                <el-dropdown-item>Delete</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>Tom</span>
        </div>
      </el-header>

      <el-main>
        <el-card v-for="(value,index) in target" :key="index">
          <el-button>target{{ index }}: {{ value }}</el-button>
        </el-card>
        <el-button @click="dialogVisible=true" >显示视频</el-button>
        <el-dialog v-model="dialogVisible" fullscreen="true" :before-close="handleClose">
          <div v-if="dialogVisible">
            <play-box :id="taskId" :target="target"></play-box>
          </div>
        </el-dialog>
      </el-main>
    </el-container>

  </el-container>

</template>

<script setup lang="ts">
import {IUser} from "@/store/pojo/IUser";
import {UserStoreModule} from "@/store/modules/User";
import getRoughListById from "@/api/task/getList/getRoughListById";
import {ref} from "vue";
import { ElMessageBox } from 'element-plus'
import PlayBox from "@/components/task/workbench/roughTask/PlayBox.vue";

const userInfo: IUser = UserStoreModule.userInfoFromSessionStorage;
const fun = getRoughListById(userInfo.id);
const roughTaskList = ref<[]>([]);
const target = ref();
const taskId = ref();
const dialogVisible = ref<boolean>(false);

fun.then((data) => {
  for (let i = 0; i < data.length; i++) {
    roughTaskList.value?.push(data[i]);
  }
  taskId.value = data[0].id;
  target.value = data[0].target.trim().split(",");
})


const handleClose = (done: () => void) => {
  ElMessageBox.confirm('确定关闭吗？ 没有提交的数据可能会丢失')
      .then(() => {
        done()
        dialogVisible.value = false;
        location.reload();
      })
      .catch(() => {
        // catch error
      })
}

const playVideo = (id: number) => {
  taskId.value = id;
}


</script>

<style scoped>

.layout-container-demo .el-header {
  position: relative;
  background-color: #b3c0d1;
  color: var(--el-text-color-primary);
}

.layout-container-demo .el-aside {
  width: 240px;

  color: var(--el-text-color-primary);
  background: #fff !important;
  border-right: solid 1px #e6e6e6;
  box-sizing: border-box;
}

.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .el-main {
  padding: 0;
}

.layout-container-demo .toolbar {
  position: absolute;
  display: inline-flex;
  align-items: center;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
}


.el-row {
  margin-bottom: 20px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.scrollbar-demo-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
  background: var(--el-color-primary-light-9);
  color: var(--el-color-primary);
}
</style>